<?php
namespace app\index\domain;

abstract class BaseList extends Base implements \Iterator
{
    var $_list      = [];

    //实现Iterator
    public function rewind()
    {
        $this->_list = $this->getList();
        if(empty($this->_list))
            $this->_list = [];
        return reset($this->_list);
    }
    
    public function current()
    {
        $objParam = current($this->_list);
        return $this->createObj($objParam);
    }
    
    public function key()
    {
        return key($this->_list);
    }
    
    public function next()
    {
        return next($this->_list);
    }
    
    public function valid()
    {
        $result = (current($this->_list) !== false);
        if(!$result){
            $this->_list = [];
            if(\think\Config::get('auto_init_param')==2&&method_exists($this, "initParam"))
                $this->initParam();
        }
        return $result;
    }

    //创建对象方法
    abstract protected function createObj($objParam);

    //获取列表方法
    abstract protected function getList();
}

